﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Raytracererer
{
    public class Plane : Primitive
    {
        public Vector3 point;
        protected Vector3 normal;

        public Plane(Vector3 point, Vector3 normal, Color color)
        {
            this.point = point;
            this.normal = normal.Normalized();
            this.color = color;
        }
        public Plane(Vector3 point, Vector3 normal, Color color, double reflectivity)
            : this(point, normal, color)
        {
            this.reflectivity = reflectivity;
        }

        Color m_color;
        double m_transparency;
        double m_reflectivity;
        double m_refractiveIndex;
        double m_diffuse;
        Color m_specularity;

        public Color color
        {
            get { return m_color; }
            set { m_color = value; }
        }
        public double transparency
        {
            get { return m_transparency; }
            set { m_transparency = value; }
        }
        public double reflectivity
        {
            get;
            set;
        }
        public double refractionIndex
        {
            get;
            set;
        }
        public double diffuse
        {
            get;
            set;
        }
        public Color specularity
        {
            get;
            set;
        }

        public double Intersect(Ray ray, out Vector3 position)
        {
            position = null;
            var denominator = normal * ray.Direction;
            if (denominator == 0)
                return -1;
            var t = normal * (point - ray.Position) / denominator;
            position = ray.Position + ray.Direction * t;
            return t;
        }

        public Vector3 Normal(Vector3 position)
        {
            return normal;
        }
        public virtual Color ColorAt(Vector3 position)
        {
            return m_color;
        }

        public bool isIn(Vector3 position)
        {
            if ((point - position) * normal > 0)
                return true;
            return false;
        }
    }
}
